@echo off
setlocal enabledelayedexpansion

set basePath=%1
set branch=%2
set buildFlag=%3
set logFile="-"
set projectPath=%basePath%\mateurp

if "%branch%" == "" (
	echo branch must be set
    exit /b 1
)

cd /d %basePath%

:: Update Code
echo Update Code Start
git checkout %branch%
git fetch origin || exit /b 1
git reset --hard "origin/%branch%" || exit /b 1
echo Update Code Finish

:: GenerateAll
echo GenerateAll Start
"C:\Program Files\Unity\Hub\Editor\2022.3.61f1c1\Editor\Unity.exe" -buildTarget Android -batchmode -nographics -quit -projectPath "%projectPath%" -executeMethod HybridCLR.Editor.BuildAssetsCommand.Prebuild -logFile %logFile% || exit /b 1
echo GenerateAll Finish

:: BuildAssets
echo BuildAssets Start
del /s /q %projectPath%\Assets\StreamingAssets
del /s /q %projectPath%\HybridCLRBuildCache\AssetBundleOutput
"C:\Program Files\Unity\Hub\Editor\2022.3.61f1c1\Editor\Unity.exe" -batchmode -nographics -quit -projectPath "%projectPath%" -executeMethod HybridCLR.Editor.BuildAssetsCommand.BuildAndCopyABAOTHotUpdateDlls -logFile %logFile% || exit /b 1
echo BuildAssets Finish

set json="{\"text\":{\"content\":\"%buildFlag%热更资源打包完成,下载地址http://%myip%/Mate/%buildFlag% \" },\"msgtype\":\"text\"}"
echo %json%
curl -H "Content-Type: application/json" -X POST -d !json! https://oapi.dingtalk.com/robot/send?access_token=1dd9ef311951334ba9e001f194f78c99ee8b74fff2c56b5f899c1727302f60b8
echo BuildStreamingAssets Finish
endlocal